package com.sk.sqd;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 具体中介者
 */
@Service
public class ConcreteMediator implements Mediator {

    /**
     * 管理具体的同事类
     */
    @Resource
    List<Colleague> colleagueList = new ArrayList<>();

    @Override
    public void sendMessage(String message, Colleague colleague) {
        for (Colleague col : colleagueList) {
            if (col == colleague) {
                // 对于自身的消息可以做其它逻辑处理
                // doSomething...
                continue;
            }
            // 其它参与者通知
            col.notify(message);
        }
    }

}
